package com.wisnews.controller.sr;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wisnews.pojo.Input;
import com.wisnews.pojo.Result;
import com.wisnews.pojo.sr.entity.Member;
import com.wisnews.pojo.sr.entity.PostInfo;
import com.wisnews.pojo.sr.vo.PostVO;
import com.wisnews.service.sr.Impl.PostInfoServiceImpl;
import com.wisnews.util.Constants;
import com.wisnews.util.DateUtil;
import com.wisnews.util.MemberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuyd
 * @since 2021-03-19
 */
@RestController
@RequestMapping("/post-info")
public class PostInfoController {

    @Autowired
    private PostInfoServiceImpl postInfoService;

    @PostMapping("/save")
    public Result savePostInfo(@RequestBody PostInfo postInfo, HttpServletRequest request){
        Member currentUser = MemberUtils.getLoginUserInfo(request);
        postInfo.setCreateTime(DateUtil.getCurrentDateTime()).setPostDataTime(DateUtil.getCurrentDateTime())
            .setPostMemberId(currentUser.getUserId());
        postInfoService.save(postInfo);
        return new Result(Constants.SYS_CODE.SUCCESS, Constants.SYS_CODE.SUCCESS_MESSAGE);
    }

    /**
     * @description: 获取列表
     * @param: input
     * @return: result
     * @author yuyd
     * @date: 2021/5/2 21:42
     */
    @PostMapping("postList")
    public Result getPostList(@RequestBody Input<PostVO> input) {

        IPage<PostVO> posts = postInfoService.getPostList(input.getReq(),input.toPage());

        return new Result(Constants.SYS_CODE.SUCCESS, Constants.SYS_CODE.SUCCESS_MESSAGE,posts);
    }



}
